package member

import (
	"errors"
	"fmt"
	"net/http"
	"oauth2/libs"
	"oauth2/repo"
	"strconv"
)

type MemberServiceImpl struct {
	userService  repo.UserRepoInterface
}



func NewMemberService() MemberServiceInterface {
	return &MemberServiceImpl{
		userService:  repo.NewUserRepo(),
	}
}


//获取用户信息
func (s *MemberServiceImpl) GetUserInfo(id int64) (interface{}, error) {
	idStr := strconv.FormatInt(id,10)
	params  := "{\"userId\" : \"" + idStr + "\"}"


	userinfo,err := libs.HttpDo(http.MethodPost,"http://localhost:9090/user/userService/GetUserInfo",params,"")
	fmt.Println("userinfo:",string(userinfo))
	if err != nil {
		return nil, errors.New("can not found user")
	}
	return userinfo, nil
}

//检验用户登录
func (s *MemberServiceImpl) CheckLogin(nickname string, password string) (interface{}, bool) {
	params  := "{\"nickname\" : \"" + nickname + "\", \"password\" : \"" + password + "\"}"
	userinfo,err := libs.HttpDo(http.MethodPost,"http://localhost:9090/user/userService/UserLogin", params,"")
	fmt.Println("userinfo:",string(userinfo))
	if err != nil {
		return userinfo, false
	}
	return userinfo, true
}
